export {}

function test(T) {
  console.log(T);
}
test('aaa')
type Res<T> ={
  msg: string
  code: number
  data: T
}

type Data = {
  goodsName: string
  price: string
}
type DataOne ={
  name: string
  gender: string
}

let goods: Res<Data> = {
  msg: '接口成功',
  code: 200,
  data: {
    goodsName: '电脑',
    price: '19.9'
  }
}
console.log(goods);

let person: Res<DataOne> = {
  msg: '接口成功',
  code: 304,
  data: {
    name: '小红',
    gender: '女'
  }
}

console.log(person);

function createArray<T>(length: number, value: T) {
  let result = []
  for (let i = 0;i< length;i ++) {
    result[i]=value
  }
  return result
}

console.log(createArray<string>(4, 'haha'));


// 定义接口
interface LengthObj {
  length: number
}

// 泛型约束
function logLen<T extends LengthObj>(obj: T) {
  console.log(obj.length)
}

logLen({a:'111',length: 10})

logLen([1,2,3,4])

logLen('100')

// logLen(true)